var status = require("../config/status.json");
/*
 *  @req.query: origin,destination,sensor(optional)
 */
function getDistance(req, res, next) {
	var google = require('../private/googleService/service');
	google.getDistance(req.query, function(err, data){
		if (!err) {
			var result = {
				'status' : 0,
				'distance' : data.routes[0].legs[0].distance,
				'duration' : data.routes[0].legs[0].duration
			};
			res.send(result);
		} else {
			var result = {
				'status' : -1
			};
			res.send(result);
		}
	});
	return next;
}


/*
 * @req.body: cus_id 
 * {'cus_id': '1'}
 */
function waiting(req, res, next){
	var result = {'status': 0};
	res.send(result);
	return next;
}

/*
 * @req.body: cus_id
 * {{'cus_id': '1'}}
 */

function cancelRequest(req, res, next){
	var result ={'status': 0};
	res.send(result);
	return next;
}
/*
 * @req.body: cus_id
 * {'cus_id': '1'}
 */

function showCustomer(req, res, next){
	return next;
}

function sendAudio(req, res, next){
	var result = new Object();
	
	result.status = status.SUCCESS.VALUE;
	result.encodedString = req.body.encodedString;
	console.log(result);
	res.send(result);
	return next
}
exports.services = [ getDistance, waiting, cancelRequest, showCustomer, sendAudio];